<template>

  <el-card>
    <!-- 三级分类导航 -->
    <el-form :disabled="isDisable"  :inline="true" :model="formInline" class="demo-form-inline">
      <el-form-item label="一级分类">
        <el-select v-model="category1Id" placeholder="请选择">
          <el-option :label="c1.name" v-for="c1 in CategorySelector.category1List " :key="c1.id" :value="c1.id" />

        </el-select>
      </el-form-item>
      <el-form-item label="二级分类">
        <el-select v-model="category2Id" placeholder="请选择">
          <el-option :label="c2.name" :value="c2.id" v-for="c2 in CategorySelector.category2List" :key="c2.id" />

        </el-select>
      </el-form-item>
      <el-form-item label="三级分类">
        <el-select v-model="category3Id" placeholder="请选择">
          <el-option :label="c3.name" :value="c3.id" v-for=" c3 in  CategorySelector.category3List" :key="c3.id" />

        </el-select>
      </el-form-item>
    </el-form>


  </el-card>
</template>

<script lang="ts">
export default {
  name: 'CategorySelector'


}
</script>

<script lang="ts" setup>
import { reactive, onMounted, computed } from 'vue'
import { useCategorySelectorStore } from "@/stores/categorySelector"
//1调用函数
const CategorySelector = useCategorySelectorStore();
defineProps(["isDisable"])

const formInline = reactive({
  user: '',
  region: '',
})

const onSubmit = () => {
  console.log('submit!')
}
//2页面以挂载就发送请求一级分类
onMounted(() => {
  //直接存储一级分类
  CategorySelector.getCategory1List()
})
//3一级分类的计算属性
const category1Id = computed({
  get() {
    return CategorySelector.category1Id as number
  },
  set(id: number) {
    //一级分类的id一旦变化，就重新请求二级数据
    CategorySelector.getCategory2List(id)

  }

});
//4二级分类的计算属性
const category2Id = computed({
  //读取

  get() {
    return CategorySelector.category2Id as number
  },
  set(id: number) {
    console.log(id)
    CategorySelector.getCategory3List(id);


  }

})
//5三级分类的计算属性
const category3Id = computed({
  get() {
    return CategorySelector.category3Id as number
  },
  set(id: number) {
    CategorySelector.SaveCategory3Id(id)
  }
})


</script>


<style lang="scss" scoped>

</style>